package com.ruoyi.community.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.community.domain.OwnerNotice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.community.mapper.OwnerVoteMapper;
import com.ruoyi.community.domain.OwnerVote;
import com.ruoyi.community.service.IOwnerVoteService;

/**
 * 业委会投票Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-08-08
 */
@Service
public class OwnerVoteServiceImpl implements IOwnerVoteService 
{
    @Autowired
    private OwnerVoteMapper ownerVoteMapper;

    /**
     * 查询业委会投票
     * 
     * @param voteId 业委会投票ID
     * @return 业委会投票
     */
    @Override
    public OwnerVote selectOwnerVoteById(String voteId)
    {
        OwnerVote resultOwnerVote = ownerVoteMapper.selectOwnerVoteById(voteId);
        Long viewNumber = resultOwnerVote.getViewNumber() + 1;
        resultOwnerVote.setViewNumber(viewNumber);
        updateOwnerVote(resultOwnerVote);
        return resultOwnerVote;
    }

    /**
     * 查询业委会投票列表
     * 
     * @param ownerVote 业委会投票
     * @return 业委会投票
     */
    @Override
    public List<OwnerVote> selectOwnerVoteList(OwnerVote ownerVote)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        ownerVote.setCommunityId(Long.valueOf(loginUser.getCommunityId()));
        return ownerVoteMapper.selectOwnerVoteList(ownerVote);
    }

    /**
     * 新增业委会投票
     * 
     * @param ownerVote 业委会投票
     * @return 结果
     */
    @Override
    public int insertOwnerVote(OwnerVote ownerVote)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        ownerVote.setCreater(loginUser.getUsername());
        ownerVote.setCommunityId(Long.valueOf(loginUser.getCommunityId()));
        return ownerVoteMapper.insertOwnerVote(ownerVote);
    }

    /**
     * 修改业委会投票
     * 
     * @param ownerVote 业委会投票
     * @return 结果
     */
    @Override
    public int updateOwnerVote(OwnerVote ownerVote)
    {
        return ownerVoteMapper.updateOwnerVote(ownerVote);
    }

    /**
     * 批量删除业委会投票
     * 
     * @param voteIds 需要删除的业委会投票ID
     * @return 结果
     */
    @Override
    public int deleteOwnerVoteByIds(String[] voteIds)
    {
        return ownerVoteMapper.deleteOwnerVoteByIds(voteIds);
    }

    /**
     * 删除业委会投票信息
     * 
     * @param voteId 业委会投票ID
     * @return 结果
     */
    @Override
    public int deleteOwnerVoteById(String voteId)
    {
        return ownerVoteMapper.deleteOwnerVoteById(voteId);
    }
}
